//引入依赖
import Vue from 'vue'
import Router from 'vue-router'
//引入组件
//import HelloWorld from '@/components/HelloWorld'
//import cart from '../components/day06Cart.vue'
//import comA from '../components/componentA.vue'
//import notF from '../components/day06notfound.vue'
//路由懒加载
const HelloWorld = () => import('../components/HelloWorld.vue')
const cart = () => import('../components/day06Cart.vue')
const comA = () => import('../components/componentA.vue')
const notF = () => import('../components/day06notfound.vue')
const index = () => import('../components/day06index.vue')
const list = () => import('../components/day06list.vue')
const detail = () => import('../components/day06detail.vue')

//当成中间件去使用
Vue.use(Router)

//路由就是路径和组件的对应关系
export default new Router({
  //哈希模式默认带井号，不想带井号+如下
  mode: 'history',
  //路由表
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      //具体渲染哪个组件
      component: HelloWorld
    },
    {
      path: '/cart',
      name: 'cart',
      component: cart
    },
    {
      path: '/comA',
      name: 'comA',
      component: comA
    },
    {
      path: '/index',
      name: 'index',
      component: index,
      children: [
        //path内不加斜线
        { path: '', component: HelloWorld },
        { path: 'cart', component: cart },
        { path: 'comA', component: comA },
      ]
    },
    {
      path: '/list',
      name: 'list',
      component: list
    },
    {
      path: '/detail/:name',
      name: 'detail',
      component: detail
    },
    //处理404页面
    {
      path: '*',
      component: notF
    }
  ]
})
